package com.huike.web.controller.report;


import com.huike.common.utils.SecurityUtils;
import com.huike.report.domain.vo.IndexTodoInfoVO;
import com.huike.report.domain.vo.IndexVo;
import com.huike.web.vo.indexVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.huike.common.core.domain.AjaxResult;
import com.huike.report.service.IReportService;

import javax.xml.crypto.Data;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;

@RestController
@RequestMapping("/index")
public class IndexController {

    @Autowired
    private IReportService reportService;


    /**
     * 首页--基础数据统计
     * @param beginCreateTime
     * @param endCreateTime
     * @return
     */
    @GetMapping("/getBaseInfo")
    public AjaxResult getBaseInfo(@RequestParam("beginCreateTime") String beginCreateTime,
                                  @RequestParam("endCreateTime") String endCreateTime){
        return AjaxResult.success(reportService.getBaseInfo(beginCreateTime,endCreateTime));
    }
//    构建了vo  查找对应的表
    @GetMapping("/getTodayInfo")
    public AjaxResult getTodayInfo(){

        indexVo vo = new indexVo();
//        今日线索 查询线索对应在今天   钱与合同数 contract
//        线索与商机  business查商机    线索clue
        //自定义格式
//        DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
//        //通过DateTimeFormatter格式化
//        LocalDateTime localDateTime = LocalDateTime.now();
//        String format = dtf.format(localDateTime);
        String format="2022-04-19";
        String username = SecurityUtils.getUsername();
        Integer row = reportService.findByContract(username,format);
        vo.setTodayContractNum(row);
        Double amount = reportService.findByContractAmount(username,format);
        vo.setTodaySalesAmount(amount);
        Integer busNum = reportService.findByBusNum(username,format);
        vo.setTodayBusinessNum(busNum);
        Integer num = reportService.findByCluesNum(username,format);
        vo.setTodayCluesNum(num);
        return AjaxResult.success(vo);
    }
//代办事物
    @GetMapping("/getTodoInfo")
    public AjaxResult getTodoInfo(@RequestParam String beginCreateTime, @RequestParam String endCreateTime){

        IndexTodoInfoVO todoInfo = reportService.getTodoInfo(beginCreateTime, endCreateTime);
        return AjaxResult.success(todoInfo);

    }

}